﻿<UserControl x:Class="RedmineTaskListPackage.View.RedmineIssueView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:vsui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.11.0"
             xmlns:local="clr-namespace:RedmineTaskListPackage.ViewModel"
             mc:Ignorable="d" 
             d:DesignHeight="350" 
             d:DesignWidth="450" 
             d:DataContext="{d:DesignData Source=../DesignData/RedmineIssue.xaml}">

    <UserControl.Resources>
        <Style x:Key="env">
            <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static local:EnvironmentColors.ToolWindowTextBrushKey}}"/>
            <Setter Property="Control.Background" Value="{DynamicResource {x:Static local:EnvironmentColors.ToolWindowBackgroundBrushKey}}"/>
            <Setter Property="Control.FontSize" Value="14"/>
        </Style>
        <BooleanToVisibilityConverter x:Key="VisibilityConverter"/>
        <local:DateTimeToElapsedConverter x:Key="ElapsedConverter" />
    </UserControl.Resources>

    <UserControl.Style>
        <Style BasedOn="{StaticResource env}" TargetType="UserControl">
            <Setter Property="Padding" Value="10,10,0,0"/>
        </Style>
    </UserControl.Style>

    <DockPanel MinHeight="160">
        <TextBlock DockPanel.Dock="Top" FontSize="20" Margin="0,0,0,7" TextTrimming="WordEllipsis">
                <Hyperlink NavigateUri="{Binding Url}" Click="OpenInBrowser">
                    <Run>
                        <MultiBinding StringFormat="{}{0} #{1}">
                            <Binding Path="TrackerName"/>
                            <Binding Path="Id"/>
                        </MultiBinding>
                    </Run>
                </Hyperlink>
                <Run>
                    <MultiBinding FallbackValue="No issue selected" StringFormat="{} {0} ({1})">
                        <Binding Path="Subject"/>
                        <Binding Path="StatusName"/>
                    </MultiBinding>
                </Run>
        </TextBlock>

        <WrapPanel DockPanel.Dock="Top" Margin="0,0,0,15">
            <TextBlock TextTrimming="WordEllipsis">
                <TextBlock.ToolTip>
                    <ToolTip Content="{Binding CreationTime}" ContentStringFormat="dd.MM.yy HH:mm:ss" />
                </TextBlock.ToolTip>
                <TextBlock.Text>
                    <MultiBinding  StringFormat="{}Created by {0} {1}. ">
                        <Binding Path="AuthorName"/>
                        <Binding Path="CreationTime" Converter="{StaticResource ElapsedConverter}"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <TextBlock TextTrimming="WordEllipsis">
                <TextBlock.ToolTip>
                    <ToolTip Content="{Binding LastUpdateTime}" ContentStringFormat="dd.MM.yy HH:mm:ss" />
                </TextBlock.ToolTip>
                <TextBlock.Text>
                    <Binding Path="LastUpdateTime" StringFormat="Updated {0}." Converter="{StaticResource ElapsedConverter}" />
                </TextBlock.Text>
            </TextBlock>
        </WrapPanel>

        <Grid DockPanel.Dock="Top" Margin="0,0,0,15" MinWidth="450">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="2*"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="2*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            
            <TextBlock Grid.Column="0" Grid.Row="0" Text="Status"/>
            <TextBlock Grid.Column="0" Grid.Row="1" Text="Priority"/>
            <TextBlock Grid.Column="0" Grid.Row="2" Text="Assignee"/>

            <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding StatusName, FallbackValue=-}"/>
            <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding PriorityName, FallbackValue=-}"/>
            <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding AssigneeName, FallbackValue=-}"/>

            <TextBlock Grid.Column="2" Grid.Row="0" Text="Start Date"/>
            <TextBlock Grid.Column="2" Grid.Row="1" Text="Due Date"/>
            <TextBlock Grid.Column="2" Grid.Row="2" Text="% Done"/>

            <TextBlock Grid.Column="3" Grid.Row="0" Text="{Binding StartDate, StringFormat={}{0:dd.MM.yy}, FallbackValue=-}"/>
            <TextBlock Grid.Column="3" Grid.Row="1" Text="{Binding DueDate, StringFormat={}{0:dd.MM.yy}, FallbackValue=-}"/>
            <WrapPanel Grid.Column="3" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Left" >
                <ProgressBar Width="100" Height="14" Value="{Binding DoneRatio}"/>
                <TextBlock Text="{Binding DoneRatio, StringFormat={}{0}%}" Margin="5,0,0,0"/>
            </WrapPanel>
        </Grid>
        
        <ScrollViewer Name="DetailsScrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
            <StackPanel>
                <TextBlock DockPanel.Dock="Top" Text="Description" Margin="0,0,0,7"
                           Visibility="{Binding DescriptionVisible, FallbackValue=Collapsed, Converter={StaticResource VisibilityConverter}, Mode=OneWay}"/>
                <TextBlock Text="{Binding Description}" Margin="15,0,0,15" TextWrapping="Wrap" Padding="0,0,15,7"
                           Visibility="{Binding DescriptionVisible, FallbackValue=Collapsed, Converter={StaticResource VisibilityConverter}, Mode=OneWay}"/>
                <TextBlock DockPanel.Dock="Top" Text="History" Margin="0,0,0,7"
                           Visibility="{Binding JournalsVisible, FallbackValue=Collapsed, Converter={StaticResource VisibilityConverter}, Mode=OneWay}"/>
                <ListView ItemsSource="{Binding Journals}"
                          Background="Transparent" BorderThickness="0" Margin="15,0,0,15"
                          ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                          Visibility="{Binding JournalsVisible, FallbackValue=Collapsed, Converter={StaticResource VisibilityConverter}, Mode=OneWay}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="0,0,0,15">
                                <TextBlock FontSize="12" Padding="0,0,15,0" Margin="0,0,0,5">
                                    <TextBlock.ToolTip>
                                        <ToolTip Content="{Binding CreationTime}" ContentStringFormat="dd.MM.yy HH:mm:ss" />
                                    </TextBlock.ToolTip>
                                    <TextBlock.Text>
                                        <MultiBinding StringFormat="{}{0} wrote {1}:">
                                            <Binding Path="AuthorName"/>
                                            <Binding Path="CreationTime" Converter="{StaticResource ElapsedConverter}"/>
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                                <TextBlock FontSize="12" Margin="15,0,0,0" Text="{Binding Notes}"  TextWrapping="Wrap" />
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackPanel>
        </ScrollViewer>
    </DockPanel>
</UserControl>
